﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bootstrapper;
using Ninject;
using SoloplanSampleApp.WebUI.Controllers;

namespace SoloplanSampleApp.WebUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel _ninjectKernel;

        public NinjectControllerFactory()
        {
            _ninjectKernel = NinjectBootsrapper.CreateAndConfigureContainer();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            return controllerType == null
                       ? null
                       : (IController) _ninjectKernel.Get(controllerType);
        }
    }
}